import { mouse, left, right, up, down, screen } from '@nut-tree/nut-js';

await mouse.move(right(500));
await mouse.move(down(500));
await mouse.move(left(500));
await mouse.move(up(500));

async function alongSpiralPath(end, circles, steps) {
    const current = await mouse.getPosition();
    const startRadius = Math.sqrt(
        Math.pow(end.x - current.x, 2) + Math.pow(end.y - current.y, 2),
    );
    const path = [];
    const fullCircle = 2 * Math.PI;
    const angleIncrement = (circles * fullCircle) / steps;
    let angle = 0;
    let radiusDecrement = startRadius / steps;

    for (let i = 0; i < steps; i++) {
        // Calculate the radius for this step
        const radius = startRadius - i * radiusDecrement;

        // Convert polar coordinates to Cartesian coordinates
        const x = end.x + radius * Math.cos(angle);
        const y = end.y + radius * Math.sin(angle);

        path.push({x, y});

        // Increment the angle for next point
        angle += angleIncrement;
    }

    return path;
}

mouse.config.mouseSpeed = 500;

const screenWidth = await screen.width();
const screenHeight = await screen.height();

const target = {
    x: screenWidth / 3,
    y: screenHeight / 4,
};

await mouse.move(alongSpiralPath(target, 5, 1000));